/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControlLayer;

import ModelLayer.Employee;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Moulde
 */
public class HelperMethods
{
    public HelperMethods()
    {
    }

    public String MD5Hash(String value)
    {
        String hashedValue = "";

        try
        {
            MessageDigest m = MessageDigest.getInstance("MD5");
            try
            {
                byte[] output = m.digest(value.getBytes("UTF-8"));

                BigInteger bigInt = new BigInteger(1, output);
                String hashtext = bigInt.toString(16);

                // Now we need to zero pad it if you actually want the full 32 chars.
                while (hashtext.length() < 32)
                {
                    hashtext = "0" + hashtext;
                }

                hashedValue = hashtext;
            }
            catch (UnsupportedEncodingException ex)
            {
                Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        catch (NoSuchAlgorithmException ex)
        {
            Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
        }

        return hashedValue;
    }
}
